<?php
/**                                          
 * 用户语言设置
 * @author M2
 * @version 1.0
 * create Date 2013-04-27
 */
class UserLangModel extends Model {
	
	/**
	 * 保存用户语言设置	
	 * @param array $langSetting
	 * @param int $uid 用户ID
	 */
	public function dosave($langSetting,$uid) {
		if(empty($uid)){
			return false;
		}
		$map['uid'] = $uid;
		$map['key'] = 'langset';
		$data['key']   = 'langset';
		$data['value'] = $langSetting['langset'];
		$res = $this->where($map)->find();
		if($res){
			$this->where($map)->save($data);
		}
		if(!$res){
			$data['uid'] = $uid;
			$this->add($data);
		}
		unset($map);unset($data);
		return true;
	}
	
	/**
	 * 获取用户语言信息	
	 * @param int $uid 用户ID
	 */
	function getUserLangSet($uid) 	{
		$userLangSet = $this->where("uid=$uid")->field('`key`,`value`')->select();
		if($userLangSet){
			foreach ($userLangSet as $k=>$v){
				$r[$v['key']] = $v['value'];
			}
			return $r;
		}else{
			return array('langset'=>'zh-cn');
		}
	}
}
?>